program bred;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement=^element;
  element=record
    value:integer;
    next:pelement;
  end;

var
  k, i, n:integer;
  head:pelement;

procedure Deletethe4th(head:pelement);
var
  current, bcurrent:pelement;
  tmp:integer;

begin
  current:=head;
  bcurrent:=head;
  tmp:=0;
  while (current^.next<>nil) do
  begin
    current:=current^.next;
    tmp:=tmp+1;
  end;
  if (tmp>=3) then
  begin
    for i:=1 to 4 do
    begin
      bcurrent:=bcurrent^.next;
      writeln(head^.next^.next^.next.value);
      dispose(head^.next^.next^.next);
      head^.next^.next^.next:=bcurrent;
    end;
  end;
end;

procedure Add(var head:pelement; num:integer);
var
  a:pelement;
begin
  a:=head;
  new(head);
  head^.next:=a;
  head^.value:=num;
end;

begin
  readln(n);
  head:=nil;
  for i:=1 to n do
  begin
    readln(k);
    Add(head, k);
  end;
  for i:=1 to n do
  begin
    Deletethe4th(head);
  end;
  readln;
  readln;
end.
